package com.ycrlkj.android.modulesbase.libbase.Rxjava;

import io.reactivex.Observable;
import io.reactivex.subjects.PublishSubject;
import io.reactivex.subjects.Subject;

public class RxBus {

    private final Subject<Object> bus;

    private static class Holder{
        private static final RxBus BUS = new RxBus();
    }

    private RxBus (){

        bus = PublishSubject.create().toSerialized();

    }

    public static RxBus get(){
        return Holder.BUS;
    }

    public void post(Object event){
        bus.onNext(event);
    }

    public <T> Observable<T> toObservable(Class<T> clazz){
        return bus.ofType(clazz);
    }


}
